#include <REGX52.H>
#include "Delay.h"
#include "Key.h"
#include "LCD1602.h"
#include "AT24C02.h"

unsigned char KeyNum;
unsigned int Num; //16位
void main()
{
	LCD_Init();
	LCD_ShowString(1,1,"Hello");	
	while(1)
	{
		KeyNum=Key();
		if(KeyNum==1)
		{
			Num++;
			LCD_ShowNum(2,1,Num,3);
		}
		if(KeyNum==2)
		{
			Num--;
			LCD_ShowNum(2,1,Num,3);
		}
		if(KeyNum==3)
		{
			AT24C02_WriteByte(0,Num%256);
			AT24C02_WriteByte(1,Num/256);
			LCD_ShowString(1,7,"Write OK");
			Delay(1000);
			LCD_ShowString(1,7,"         ");
		}
		if(KeyNum==4)
		{
			Num=AT24C02_ReadByte(0);//低八位赋值
			Num |= AT24C02_ReadByte(1)<<8;//高八位赋值
			LCD_ShowNum(2,1,Num,3);
			LCD_ShowString(1,7,"Read OK");
			Delay(1000);
			LCD_ShowString(1,7,"        ");
		}
		else
		{
			LCD_ShowNum(2,1,Num,3);	
		}
	}
}